package com.lwj.framework.entity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AuthProperties {
	List<String> name = new ArrayList<String>();
	List<String> clientId = new ArrayList<String>();
	List<String> secret = new ArrayList<String>();
	List<String[]> grantTypes = new ArrayList<String[]>();
	List<String[]> authorities = new ArrayList<String[]>();
	List<String[]> scopes = new ArrayList<String[]>();
	List<Integer> accessTokenValiditySeconds = new ArrayList<Integer>();
	List<Integer> refreshTokenValiditySeconds = new ArrayList<Integer>();
	List<Boolean> tokenStore = new ArrayList<Boolean>();

	Map<String, AuthEntity> clientIdMap = null;
	Map<String, AuthEntity> clientNameMap = null;

	void initEntityMap() {
		if (clientNameMap == null) {
			synchronized (this) {
				if (clientNameMap == null) {
					clientIdMap = new HashMap<String, AuthEntity>();
					clientNameMap = new HashMap<String, AuthEntity>();
					for (int i = 0; i < name.size(); ++i) {
						AuthEntity entity = new AuthEntity();
						entity.setName(name.get(i));
						entity.setClientId(clientId.get(i));
						entity.setSecret(secret.get(i));
						entity.setGrantTypes(grantTypes.get(i));
						entity.setAuthorities(authorities.get(i));
						entity.setScopes(scopes.get(i));
						entity.setAccessTokenValiditySeconds(accessTokenValiditySeconds.get(i));
						entity.setRefreshTokenValiditySeconds(refreshTokenValiditySeconds.get(i));
						entity.setTokenStore(tokenStore.get(i));
						clientNameMap.put(name.get(i), entity);
						clientIdMap.put(clientId.get(i), entity);
					}
				}
			}
		}
	}

	public AuthEntity getAuthByName(String clientName) {
		initEntityMap();
		return clientNameMap.get(clientName);
	}

	public AuthEntity getAuthById(String clientid) {
		initEntityMap();
		return clientIdMap.get(clientid);
	}

	public Collection<AuthEntity> getAuthList() {
		initEntityMap();
		return clientNameMap.values();
	}

	public List<String> getName() {
		return name;
	}

	public void setName(List<String> name) {
		this.name = name;
	}

	public List<String> getClientId() {
		return clientId;
	}

	public void setClientId(List<String> clientId) {
		this.clientId = clientId;
	}

	public List<String> getSecret() {
		return secret;
	}

	public void setSecret(List<String> secret) {
		this.secret = secret;
	}

	public List<String[]> getGrantTypes() {
		return grantTypes;
	}

	public void setGrantTypes(List<String[]> grantTypes) {
		this.grantTypes = grantTypes;
	}

	public List<String[]> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(List<String[]> authorities) {
		this.authorities = authorities;
	}

	public List<String[]> getScopes() {
		return scopes;
	}

	public void setScopes(List<String[]> scopes) {
		this.scopes = scopes;
	}

	public List<Integer> getAccessTokenValiditySeconds() {
		return accessTokenValiditySeconds;
	}

	public void setAccessTokenValiditySeconds(List<Integer> accessTokenValiditySeconds) {
		this.accessTokenValiditySeconds = accessTokenValiditySeconds;
	}

	public List<Integer> getRefreshTokenValiditySeconds() {
		return refreshTokenValiditySeconds;
	}

	public void setRefreshTokenValiditySeconds(List<Integer> refreshTokenValiditySeconds) {
		this.refreshTokenValiditySeconds = refreshTokenValiditySeconds;
	}

	public List<Boolean> getTokenStore() {
		return tokenStore;
	}

	public void setTokenStore(List<Boolean> tokenStore) {
		this.tokenStore = tokenStore;
	}
}
